package leetcode_1_200;

public class LeeCode_91_timeout {
    public static void main(String[] args) {
        System.out.println(numDecodings("0001"));
    }
    private static int numDecodings(String s) {
        int[] res = new int[1];
        search(s, 0, res);
        return res[0];
    }
    private static  void search(String s, int index, int[] res){
        if (index >= s.length()){
            res[0] += 1;
            return;
        }
        char fir = s.charAt(index);
        if (fir == '0')
            return;
        search(s, index + 1, res);
        if (index + 1 >= s.length()){
            return;
        }
        char sec = s.charAt(index + 1);
        int num = Integer.parseInt(fir + "" + sec);
        if (num > 26)
            return;
        search(s, index + 2, res);
    }
}
